<?php

class Gorilla_Controller_Action_Helper_Pdf extends Zend_Controller_Action_Helper_Abstract
{
 
 	public function direct($pdf, $filename = null) {
	
		require_once 'Zend/Controller/Action/HelperBroker.php';
	    
	    if (null == $filename) {
				$filename = rand().'.pdf';
	    }
	    
	    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
	    $viewRenderer->setNoRender(true);
	  
	  	$layout = Zend_Controller_Action_HelperBroker::getStaticHelper('layout');
	    $layout->disableLayout(true);

		$response = $this->getResponse();
        $data = $pdf->render();
        $size = 0;
        
        $response->setHeader('Expires','Mon, 20 May 1974 23:58:00 GMT')
					->setHeader('Last-Modified', gmdate('D, d M Y H:i:s') . ' GMT')
					->setHeader('Cache-Control','no-store, no-cache, must-revalidate')
					->setHeader('Cache-Control','post-check=0, pre-check=0', false)
					->setHeader('Cache-Control','private')
					->setHeader('Pragma','no-cache')
					->setHeader('Content-Type','application/pdf')
					->setHeader('Content-Transfer-Encoding','binary')
				    /* ->setHeader('Content-disposition',sprintf('attachment; filename="%s"', $filename)) */
				    ->setBody($data)
       			    ->sendResponse();
       		
	}
}
